#include "RenderObject.h"

RenderObject::RenderObject() : speed ( 10 ), friction ( 0.99f )
{

	hge = hgeCreate(HGE_VERSION);
	quad.tex=hge->Texture_Load("particles.png");

	if (!quad.tex)
	{
		//MessageBox(NULL, "Can't load particles.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
	}

	quad.blend=BLEND_ALPHAADD | BLEND_COLORMUL | BLEND_ZWRITE;

	for(int i=0;i<4;i++)
	{
		// Set up z-coordinate of vertices
		quad.v[i].z=0.5f;
		// Set up color. The format of DWORD col is 0xAARRGGBB
		quad.v[i].col=0xFFFFA000;
	}

	x = 400;
	y = 300;

	quad.v[0].tx=96.0/128.0; quad.v[0].ty=64.0/128.0;
	quad.v[1].tx=128.0/128.0; quad.v[1].ty=64.0/128.0;
	quad.v[2].tx=128.0/128.0; quad.v[2].ty=96.0/128.0;
	quad.v[3].tx=96.0/128.0; quad.v[3].ty=96.0/128.0;

	quad.v[0].x= 400; quad.v[0].y= 300;
    quad.v[1].x= 432; quad.v[1].y= 300;
    quad.v[2].x= 432; quad.v[2].y= 332;
    quad.v[3].x= 400; quad.v[3].y= 332;
}

RenderObject::~RenderObject()
{
	hge->Texture_Free(quad.tex);
	hge->Release();
}

void RenderObject::updateCoords()
{
	if(x>784) {x=784-(x-784);dx=-dx;}
	if(x<16) {x=16+16-x;dx=-dx;}
	if(y>584) {y=584-(y-584);dy=-dy;}
	if(y<16) {y=16+16-y;dy=-dy;}

	dx*=friction; dy*=friction; x+=dx; y+=dy;
	quad.v[0].x=x-16; quad.v[0].y=y-16;
	quad.v[1].x=x+16; quad.v[1].y=y-16;
	quad.v[2].x=x+16; quad.v[2].y=y+16;
	quad.v[3].x=x-16; quad.v[3].y=y+16;
}

void RenderObject::setDx(float newDx)
{
	dx+=newDx;
}

void RenderObject::setDy(float newDy)
{
	dy+=newDy;
}
